def gen_numbers(N:int, M:int, prefix=None):

    if M == 0:
        print(prefix)
        return

    prefix = prefix or []
    
    for digit in range(N):
        prefix.append(digit)
        gen_numbers(N, M-1, prefix)
        prefix.pop()

gen_numbers(5, 2)
# gen_numbers(10, 3)
